package com.enjoy.james.controller;

import com.enjoy.james.annotation.EnjoyAutowired;
import com.enjoy.james.annotation.EnjoyController;
import com.enjoy.james.annotation.EnjoyRequestMapper;
import com.enjoy.james.annotation.EnjoyRequestParam;
import com.enjoy.james.service.JamesService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;

/**
 * Title: Projects
 * About:
 * Other:
 * Created: tyy on 9:50 2019/2/22
 * Editored:
 */
@EnjoyController
@EnjoyRequestMapper("/james")
public class JamesController {
    @EnjoyAutowired("jamesService")
    private JamesService jamesService;

    @EnjoyRequestMapper("/query")
    public void query(HttpServletRequest request, HttpServletResponse response,
                      @EnjoyRequestParam("name")String name,
                      @EnjoyRequestParam("age")String age){
        try {
            PrintWriter pw = response.getWriter();
            String result = jamesService.query(name, age);
            pw.write(result);
        }catch (Exception e){
            System.out.println("出现了异常");
            e.printStackTrace();

        }
    }
    @EnjoyRequestMapper("/query2")
    public void query2(HttpServletRequest request, HttpServletResponse response){
        try {
            PrintWriter pw = response.getWriter();
            pw.write("query2.....");
        }catch (Exception e){
            System.out.println("出现了异常");
            e.printStackTrace();

        }
    }
}
